//
//  SHYCommonTool
//  Pods
//
//  Created by sunhaiyan on 16/6/28.
//
//

#import "NSString+MD5.h"
#import <CommonCrypto/CommonDigest.h>

@implementation NSString (MD5)

- (NSString *)MD5 {
    
    NSMutableString *MD5String;
    
    if (self.length) {
        const char *value = [self UTF8String];
        
        unsigned char outputBuffer[CC_MD5_DIGEST_LENGTH];
        CC_MD5(value, (CC_LONG)strlen(value), outputBuffer);
        
        MD5String = [[NSMutableString alloc] initWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
        
        for (NSInteger count = 0; count < CC_MD5_DIGEST_LENGTH; count++) {
            [MD5String appendFormat:@"%02x", outputBuffer[count]];
        }
    }

    return MD5String;
}


@end
